﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using App1AppHandler;
using System.IO;
using System.Xml;

namespace Reborn_WorldServer.App1AppHandler
{
    public class MailBoxData
    {
        public List<Loot> myItems = new List<Loot>();
        public List<MailItem> mailBoxItems = new List<MailItem>();

        public string toXML(Character sendingToCharacter)
        {
            string result = "";

            StringWriter stringWriter = new StringWriter();
            XmlTextWriter xmldoc = new XmlTextWriter(stringWriter);

            xmldoc.WriteStartElement("mailboxdata");
            
            xmldoc.WriteStartElement("myitems");
            foreach (Loot loot in myItems)
                xmldoc.WriteRaw(loot.toXML(sendingToCharacter));
            xmldoc.WriteEndElement();

            xmldoc.WriteStartElement("mailboxitems");
            foreach (MailItem mailItem in mailBoxItems)
                xmldoc.WriteRaw(mailItem.toXML(sendingToCharacter));
            xmldoc.WriteEndElement();

            xmldoc.WriteEndElement();
            xmldoc.Flush();

            xmldoc.Close();

            stringWriter.Flush();

            result = stringWriter.ToString();

            return result;
        }
    }
}
